home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / OS / FWGraphx / Include / FWFont.h < prev    next >
Encoding:
Text File  |  1996-08-16  |  7.9 KB  |  282 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWFont.h
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWFONT_H
  11. #define FWFONT_H
  12.  
  13. #ifndef SLGRDEF_H
  14. #include "SLGrDef.h"
  15. #endif
  16.  
  17. #ifndef FWSTDDEF_H
  18. #include "FWStdDef.h"
  19. #endif
  20.  
  21. #ifndef FWGCONST_H
  22. #include "FWGConst.h"
  23. #endif
  24.  
  25. #ifndef FWCOLOR_H
  26. #include "FWColor.h"
  27. #endif
  28.  
  29. #ifndef FWGC_H
  30. #include "FWGC.h"
  31. #endif
  32.  
  33. #ifndef SLGDEV_H
  34. #include "SLGDev.h"
  35. #endif
  36.  
  37. #ifndef SLSHATTR_H
  38. #include "SLShAttr.h"
  39. #endif
  40.  
  41. #ifndef FWGRREF_H
  42. #include "FWGrRef.h"
  43. #endif
  44.  
  45. // ----- Foundation Includes -----
  46.  
  47. #ifndef FWSTRING_H
  48. #include "FWString.h"
  49. #endif
  50.  
  51. //========================================================================================
  52. //    Forward Class Declarations
  53. //========================================================================================
  54.  
  55. class FW_CReadableStream;
  56. class FW_CWritableStream;
  57.  
  58. //========================================================================================
  59. //    class FW_CFontMetrics
  60. //========================================================================================
  61. //    For an explanation of why I divide everything by 20 on Windows, look at 
  62. //    FW_CFontMetrics::PrivGetFontMetrics
  63.  
  64. class FW_CFontMetrics : public FW_PlatformFontMetrics
  65. {
  66. public:
  67.     short    GetAscent() const;
  68.     short    GetDescent() const;
  69.     short    GetInternalLeading() const;
  70.     short    GetExternalLeading() const;
  71.     short    GetFontHeight() const;
  72.     short    GetLineSpacing() const;
  73.     
  74.     static void    PrivGetFontMetrics(FW_HGDevice device, FW_CFontMetrics& fontMetrics);
  75. };
  76.  
  77. //----------------------------------------------------------------------------------------
  78. //    FW_CFontMetrics::GetLineSpacing
  79. //----------------------------------------------------------------------------------------
  80. inline short FW_CFontMetrics::GetLineSpacing() const
  81. {
  82. #ifdef FW_BUILD_MAC
  83.     return ascent + descent + leading;
  84. #endif
  85. #ifdef FW_BUILD_WIN
  86.     return tmHeight / 20;
  87. #endif
  88. }
  89.  
  90. //----------------------------------------------------------------------------------------
  91. //    FW_CFontMetrics::GetAscent
  92. //----------------------------------------------------------------------------------------
  93. inline short FW_CFontMetrics::GetAscent() const
  94. {
  95. #ifdef FW_BUILD_MAC
  96.     return ascent;
  97. #endif
  98. #ifdef FW_BUILD_WIN
  99.     return tmAscent / 20;
  100. #endif
  101. }
  102.  
  103. //----------------------------------------------------------------------------------------
  104. //    FW_CFontMetrics::GetDescent
  105. //----------------------------------------------------------------------------------------
  106. inline short FW_CFontMetrics::GetDescent() const
  107. {
  108. #ifdef FW_BUILD_MAC
  109.     return descent;
  110. #endif
  111. #ifdef FW_BUILD_WIN
  112.     return tmDescent / 20;
  113. #endif
  114. }
  115.  
  116. //----------------------------------------------------------------------------------------
  117. //    FW_CFontMetrics::GetExternalLeading
  118. //----------------------------------------------------------------------------------------
  119. inline short FW_CFontMetrics::GetExternalLeading() const
  120. {
  121. #ifdef FW_BUILD_MAC
  122.     return 0;
  123. #endif
  124. #ifdef FW_BUILD_WIN
  125.     return tmExternalLeading / 20;
  126. #endif
  127. }
  128.  
  129. //----------------------------------------------------------------------------------------
  130. //    FW_CFontMetrics::GetInternalLeading
  131. //----------------------------------------------------------------------------------------
  132. inline short FW_CFontMetrics::GetInternalLeading() const
  133. {
  134. #ifdef FW_BUILD_MAC
  135.     return leading;
  136. #endif
  137. #ifdef FW_BUILD_WIN
  138.     return tmInternalLeading / 20;
  139. #endif
  140. }
  141.  
  142. //----------------------------------------------------------------------------------------
  143. //    FW_CFontMetrics::GetFontHeight
  144. //----------------------------------------------------------------------------------------
  145. inline short FW_CFontMetrics::GetFontHeight() const
  146. {
  147. #ifdef FW_BUILD_MAC
  148.     return ascent + descent;
  149. #endif
  150. #ifdef FW_BUILD_WIN
  151.     return (tmHeight - tmInternalLeading) / 20;
  152. #endif
  153. }
  154.  
  155. //========================================================================================
  156. //    CLASS FW_CFont
  157. //========================================================================================
  158.  
  159. class FW_CFont : public FW_TGrRefPtr<FW_HFont>
  160. {
  161. public:
  162.     FW_DECLARE_AUTO(FW_CFont)
  163.  
  164.     FW_CFont(FW_EStandardFonts std = FW_kNormalFont);
  165.     FW_CFont(const FW_CString& fontName, FW_FontStyle fontStyle, FW_Fixed fontSize);
  166.     FW_CFont(const FW_CFont& other);
  167.     
  168.     ~FW_CFont();
  169.  
  170.     FW_CFont& operator=(const FW_CFont& other);
  171.  
  172.     FW_CFont& operator=(FW_EStandardFonts std);
  173.     
  174.     FW_CFont    Copy() const;
  175.  
  176.     friend FW_CWritableStream& operator << (FW_CWritableStream& stream, const FW_CFont& font);
  177.     friend FW_CReadableStream& operator >> (FW_CReadableStream& stream, FW_CFont& font);
  178.  
  179.     void                GetFontMetrics(FW_HGDevice device, FW_CFontMetrics& fontMetrics) const;
  180.     void                GetFontMetrics(FW_CGraphicContext& gc, FW_CFontMetrics& fontMetrics) const;
  181.  
  182.     // ----- Delegation
  183.  
  184.     long                GetRefCount() const;
  185.  
  186.     // Attributes
  187.     
  188.     FW_Fixed            GetFontSize() const;
  189.     FW_FontStyle        GetFontStyle() const;
  190.     void                GetFontName(FW_CString& fontName) const;
  191.     
  192.     // Comparison
  193.     
  194.     FW_Boolean            IsEqual(const FW_CFont& font2) const;
  195.     
  196.     // Operations
  197.     
  198.     void                SetFontSize(FW_Fixed size);
  199.     void                SetFontStyle(FW_FontStyle style);
  200.     void                SetFontName(const FW_CString& fontName);
  201.     
  202.     // Macintosh-only
  203. #ifdef FW_BUILD_MAC
  204.     short                MacGetFontID() const;
  205.     Style                MacGetFontStyle() const;
  206. #endif
  207. };
  208.  
  209. //========================================================================================
  210. //    Inlines
  211. //========================================================================================
  212.  
  213. //----------------------------------------------------------------------------------------
  214. //    FW_CFont::GetRefCount
  215. //----------------------------------------------------------------------------------------
  216. inline long FW_CFont::GetRefCount() const
  217. {
  218.     return FW_PrivFont_GetRefCount(fRep);
  219. }
  220.  
  221. //----------------------------------------------------------------------------------------
  222. //    FW_CFont::GetFontSize
  223. //----------------------------------------------------------------------------------------
  224. inline FW_Fixed FW_CFont::GetFontSize() const
  225. {
  226.     return FW_PrivFont_GetSize(fRep);
  227. }
  228.  
  229. //----------------------------------------------------------------------------------------
  230. //    FW_CFont::GetFontStyle
  231. //----------------------------------------------------------------------------------------
  232. inline FW_FontStyle FW_CFont::GetFontStyle() const
  233. {
  234.     return FW_PrivFont_GetStyle(fRep);
  235. }
  236.  
  237. //----------------------------------------------------------------------------------------
  238. //    FW_CFont::IsEqual
  239. //----------------------------------------------------------------------------------------
  240. inline FW_Boolean FW_CFont::IsEqual(const FW_CFont& font2) const
  241. {
  242.     return FW_PrivFont_IsEqual(fRep, font2.fRep);
  243. }
  244.  
  245. //----------------------------------------------------------------------------------------
  246. //    FW_CFont::SetFontSize
  247. //----------------------------------------------------------------------------------------
  248. inline void FW_CFont::SetFontSize(FW_Fixed size)
  249. {
  250.     FW_PrivFont_SetSize(fRep, size);
  251. }
  252.  
  253. //----------------------------------------------------------------------------------------
  254. //    FW_CFont::SetFontStyle
  255. //----------------------------------------------------------------------------------------
  256. inline void FW_CFont::SetFontStyle(FW_FontStyle style)
  257. {
  258.     FW_PrivFont_SetStyle(fRep, style);
  259. }
  260.  
  261. #ifdef FW_BUILD_MAC
  262. //----------------------------------------------------------------------------------------
  263. //    FW_CFont::MacGetFontID
  264. //----------------------------------------------------------------------------------------
  265. inline short FW_CFont::MacGetFontID() const
  266. {
  267.     return FW_PrivFont_MacGetFontID(fRep);
  268. }
  269. #endif
  270.  
  271. #ifdef FW_BUILD_MAC
  272. //----------------------------------------------------------------------------------------
  273. //    FW_CFont::MacGetFontStyle
  274. //----------------------------------------------------------------------------------------
  275. inline Style FW_CFont::MacGetFontStyle() const
  276. {
  277.     return FW_PrivFont_MacGetFontStyle(fRep);
  278. }
  279. #endif
  280.  
  281. #endif
  282.